package com.self.liu.xp.base;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/*
 * Thrift服务应用程序
 */
public class ThriftApplication {

    private static final String THRIFT_SERVER_FILENAME = "thrift-server.xml";

    private static ClassPathXmlApplicationContext serverContext = null;

    /*
     * 启动服务
     * 
     * 注：创建Spring容器=>创建ServiceBean=>启动服务。
     */
    public static void start() {
        if (serverContext == null) {
            serverContext = new ClassPathXmlApplicationContext(THRIFT_SERVER_FILENAME);
        }
        serverContext.start();
    }

    /*
     * 停止服务
     * 
     * ThriftServiceBean 销毁清除
     */
    public static void stop() {
        if (serverContext != null) {
            //销毁所有Bean
            serverContext.destroy();
            serverContext.stop();
            serverContext = null;
        }
    }
}
